var pushupsetcontroller = {

    setNum : 1,

    loadDayContent : function (){
        var output = "<h3>You are in set "+ pushupsetcontroller.setNum +"</h3><br/><h2> and you have to do ";
        output += localStorage.getItem('Set'+pushupsetcontroller.setNum);
        output+=" pushups</h2>";
        $.mobile.activePage.find("#set_details").html(output);
    },

    startNextSet : function(){
        pushupsetcontroller.setNum++;
        alert("Well done! +10 points.");
        pushupsetcontroller.addPoints(10);
        if(localStorage.getItem("SetsTotal") < pushupsetcontroller.setNum){
            alert("You completed all sets! You win 100 extra points!");
            pushupsetcontroller.addPoints(100);
            pushupsetcontroller.setNextDay();
            pushupsetcontroller.setNum=1;
            $.mobile.changePage( 'profile.html', { transition: 'slide', changeHash: false });
        }else{
            pushupsetcontroller.loadDayContent();
        }
    },

    setNextDay : function(){
        if(localStorage.getItem("day_num") == "1"){
            localStorage.setItem("day_num", 2);
        }else if(localStorage.getItem("day_num") == "2"){
            localStorage.setItem("day_num", 3);
        }else{
            var week = localStorage.getItem("week_num");
            localStorage.setItem("week_num", ++week);
            localStorage.setItem("day_num", 1);
        }
    },

    addPoints : function( points ){
        if(localStorage.getItem("total_points") === null){
            localStorage.setItem("total_points", points);
        }else{
            var temp = localStorage.getItem("total_points");
            temp = parseInt(temp)+points;
            localStorage.setItem("total_points", temp);
        }
    }
}
